package com.lipaluma.excel.config;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

import org.apache.commons.io.input.ReaderInputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public enum ExcelExtension {
	XLS {
		@Override
		public Workbook createWorkbook() {
			return new HSSFWorkbook();
		}
		@Override
		public Workbook createWorkbook(InputStream in) throws IOException {
			return new HSSFWorkbook(in);
		}
		@Override
		public Workbook createWorkbook(Reader reader) throws IOException {
			return new HSSFWorkbook(new ReaderInputStream(reader));
		}
	}, 
	XLSX {
		@Override
		public Workbook createWorkbook() {
			return new XSSFWorkbook();
		}
		@Override
		public Workbook createWorkbook(InputStream in) throws IOException {
			return new XSSFWorkbook(in);
		}
		@Override
		public Workbook createWorkbook(Reader reader) throws IOException {
			return new XSSFWorkbook(new ReaderInputStream(reader));
		}
	};

	public abstract Workbook createWorkbook();
	
	public abstract Workbook createWorkbook(InputStream in) throws IOException;

	public abstract Workbook createWorkbook(Reader reader) throws IOException;
}
